<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>博客文章</title>
    <script th:src="@{/js/vue.js}" type="text/javascript"></script>
    <script th:src="@{/js/axios.js}" type="text/javascript"></script>
<<<<<<< HEAD
    <link th:href="@{/css/head.css}" rel="stylesheet" type="text/css"></link>
    <style>
        body {
            font-size: 12px;
            margin-right: 0px;
            padding-bottom: 10px;
            font-family: Verdana;
            margin: 0;
            padding: 0;
            /* background-color: #EEEEFF; */
        }


=======
    <style>
        body {
            font-size: 13px;
            font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
            margin-left: 30px;
            margin-right: 30px;
            margin-top: 10px;
            margin-bottom: 10px;
            padding: 30px;
            padding-bottom: 10px;
            padding-top: 10px;
            background-color: #D9D6CB;
            word-wrap: break-word;
        }

>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
        table {
            display: table;
            border-collapse: separate;
            box-sizing: border-box;
            text-indent: initial;
            white-space: normal;
            line-height: normal;
            font-weight: normal;
            font-size: medium;
            font-style: normal;
            color: -internal-quirk-inherit;
            text-align: start;
            border-spacing: 2px;
            border-color: grey;
            font-variant: normal;
        }

        table[Attributes Style

        ]
        {
            width: 100%
        ;
            -webkit-border-horizontal-spacing: 0px
        ;
            -webkit-border-vertical-spacing: 0px
        ;
        }
        .Framework {
            border: 1px solid black;
            background-color: #EEEEEE;
        }

        #top {
            background-color: rgb(128, 175, 39) !important;
            height: 75px;
            vertical-align: middle;
            color: #ccc;
            padding-left: 10px;
            background-image: url();
        }

        td {
            font-size: 12px;
            display: table-cell;
            vertical-align: inherit;
        }

        td[Attributes Style

        ]
        {
            width: 100%
        ;
        }
        #top td {
            color: white;
            filter: shadow(color=#002244, direction=120, enabled=1, strength=3) glow(color=#2B446F, enabled=1, strength=1);
            text-align: left;
        }

        #top h1 {
            font-weight: normal;
        }

        h1 {
            margin: 0px;
            padding-top: 5px;
            font-size: 1.8em;
            display: block;
            font-size: 2em;
            margin-block-start: 0.67em;
            margin-block-end: 0.67em;
            margin-inline-start: 0px;
            margin-inline-end: 0px;
            font-weight: bold;
        }

        h1 a:visited, h1 a:active, h1 a:link, h1 a:hover {
            color: #FFF;
            /* margin-left: 10px; */
            margin-top: 10px;
            text-decoration: none;
        }

        .headermaintitle {
            font-family: "Trebuchet MS";
        }

        a {
            color: #223355;
            text-decoration: none;
        }

        a:-webkit-any-link {
            color: -webkit-link;
            cursor: pointer;
            text-decoration: underline;
        }

        .LeftCell {
            width: 200px;
            vertical-align: top;
        }

        #leftmenu {
            left: 0px;
            width: 180px;
            padding: 0px;
            padding-bottom: 5px;
        }

        #leftmenu h3 {
            font-size: 1em;
            margin: 0px;
            padding: 4px;
            /*background-image: url(images/ColumnHeaderBg.gif);*/
            /*background-repeat: repeat-x;*/
            color: #666666;
        }

        h3 {
            display: block;
            font-size: 1.17em;
            margin-block-start: 1em;
            margin-block-end: 1em;
            margin-inline-start: 0px;
            margin-inline-end: 0px;
            font-weight: bold;
        }

        #leftmenu ul {
            list-style: none;
            margin: 0px;
            padding: 0px;
            margin-left: 8px;
            margin-bottom: 10px;
            font-size: 13px;
            width: 100%;
        }

        ul {

            display: block;
            margin-block-start: 1em;
            margin-block-end: 1em;
            margin-inline-start: 0px;
            margin-inline-end: 0px;
            padding-inline-start: 40px;
        }

        #leftmenu li {
            margin-top: 6px;
        }

        li {
            display: list-item;
            text-align: -webkit-match-parent;
        }

        .MainCell {
            border-left: 1px solid #DDDDDD;
            border-bottom: 1px solid #DDDDDD;
            padding: 10px;
            background-color: White;
            vertical-align: top;
        }

        .post {
            border: 1px solid #CCCCCC;
            border-bottom-width: 2px;
            border-right-width: 2px;
            padding: 0px;
            margin-bottom: 28px;
        }

        .posthead {
            background-color: #EEEEEE;
            background-position: bottom;
            background-repeat: repeat-x;
            border-bottom: 1px solid #CCCCCC;
            padding: 4px;
            color: #444444;
            font-size: 9px;
        }

        .posthead h2 {
            font-size: 13px;
            margin: 0px;
        }

        h2 {
            display: block;
            font-size: 1.5em;
            margin-block-start: 0.83em;
            margin-block-end: 0.83em;
            margin-inline-start: 0px;
            margin-inline-end: 0px;
            font-weight: bold;
        }

        a {
            color: #223355;
            text-decoration: none;
        }

        a:-webkit-any-link {
            color: -webkit-link;
            cursor: pointer;
            text-decoration: underline;
        }

        #leftmenu a {
            text-decoration: none;
            color: #223355;
        }

        .ipt-txt {
            font-size: 12px;
            display: inline-block;
            box-sizing: border-box;
            background-color: #f4f5f7;
            border: 1px solid #e5e9ef;
            overflow: auto;
            border-radius: 4px;
            color: #555;
            width: 100%;
            height: 65px;
            transition: 0s;
            padding: 5px 10px;
            line-height: normal;
            outline: none;
        }

        button {
            cursor: pointer
        }

        .answerson a {
            text-decoration: none;
        }
    </style>
</head>
<body>
<div id="app">
<<<<<<< HEAD
    <div th:include="~{common/head::head}"></div>
=======
>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
    <table width="100%" class="Framework" cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
            <td colspan="2">
                <div id="top">
                    <table width="100%" cellpadding="8" cellspacing="0">
                        <tbody>
                        <tr>
                            <td nowrap>
                                <h1>
                                    <a class="headermaintitle" href="javascript:void(0)">{{respMap.blog.author}}</a>
                                </h1>
                            </td>
                        </tr>
                        </tbody>
                    </table>
                </div>
            </td>
        </tr>
        <tr>
            <td class="LeftCell">
                <div id="leftmenu" style="display: inline-block">
                    <h2><a href="/api/public/go2Index">首页</a></h2>
                </div>
            </td>
            <td class="MainCell" width="100%">
                <div id="main">
                    <div class="post">
                        <div class="posthead">
                            <h2>
                                标题:{{respMap.blog.title}}
                            </h2>
                            发表时间:{{respMap.blog.tcreate}}
                            &nbsp;&nbsp;
                            作者:{{respMap.blog.author}}
                            &nbsp;&nbsp;
                            阅读:{{respMap.blog.readnum}}
                            &nbsp;&nbsp;
                            点赞:{{respMap.blog.likenum}}
                        </div>
                        <div class="postbody" v-html="respMap.body.content">

                        </div>
                    </div>
                </div>
<<<<<<< HEAD
                <button @click="addLike()" th:if="${session.SPRING_SECURITY_CONTEXT}!=null">点赞</button>
                <hr>
                <div th:if="${session.SPRING_SECURITY_CONTEXT}!=null">
                    <textarea  cols="80" name="msg" rows="5" placeholder="发一条友善的评论" class="ipt-txt"
                               v-model="comment.content" ></textarea>
                    <button @click="commentOnBlog()">发表评论</button>
                    <hr>
                </div>
                <h2>{{respMap.blog.commentnum}}&nbsp;&nbsp;评论</h2>
                <hr>
                <div v-for="(obj,idx) in respMap.blog.comments">
=======
                <button @click="addLike()">点赞</button>
                <hr>
                <textarea cols="80" name="msg" rows="5" placeholder="发一条友善的评论" class="ipt-txt"
                          v-model="answer.content"></textarea>
                <button @click="answer2Blog()">发表评论</button>
                <hr>
                <h2>{{respMap.blog.answernum}}&nbsp;&nbsp;评论</h2>
                <hr>
                <div v-for="(obj,idx) in answers">
>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
                    <hr>
                    <p><b>{{obj.nickname}}:</b></p>
                    <p>{{obj.content}}</p>
                    <p style="color: #99a2aa" class="answerson">{{obj.tcreate}}&nbsp;&nbsp;<a href="javascript:void(0)"
<<<<<<< HEAD
                                                                                              @click="changeCommentid(obj.id)">回复</a>
=======
                                                                                              @click="replay(obj.id)">回复</a>
>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
                    </p>
                    <div style="height: 1vh"></div>
                    <div class="answers">

<<<<<<< HEAD
                        <div v-for="item in obj.replays">
                            <p>&nbsp;&nbsp;&nbsp;{{item.nickname}} &nbsp;&nbsp;回复&nbsp;&nbsp;<span style="color:#00a1d6">@{{item.nickname2}}</span>:{{item.content2}}&nbsp;&nbsp;:{{item.content}}&nbsp;&nbsp;<a href="javascript:void(0)"
                                                                                                                                               @click="changeCommentid2(obj.id,item.id)">回复</a></p>
                            <p style="color: #99a2aa" class="answerson">&nbsp;&nbsp;&nbsp;{{item.tcreate}}</p>
                        </div>
                    </div>
                    <div v-if="commentid==obj.id">
                        <textarea cols="80" name="msg" rows="5" placeholder="发一条友善的评论" class="ipt-txt"
                                  v-model="replay.content"></textarea>
                        <button @click="replay2Comment(obj.id,idx)">回复</button>
=======
                        <div v-for="item in obj.answers">
                            <p>&nbsp;&nbsp;&nbsp;{{item.nickname}} &nbsp;&nbsp;回复&nbsp;&nbsp;<span style="color:#00a1d6">@{{item.nickname2}}</span>:{{item.content2}}&nbsp;&nbsp;:{{item.content}}&nbsp;&nbsp;<a href="javascript:void(0)"
                                                                                                                                               @click="replay2(obj.id,item.id)">回复</a></p>
                            <p style="color: #99a2aa" class="answerson">&nbsp;&nbsp;&nbsp;{{item.tcreate}}</p>
                        </div>
                    </div>
                    <div v-if="answerid==obj.id">
                        <textarea cols="80" name="msg" rows="5" placeholder="发一条友善的评论" class="ipt-txt"
                                  v-model="answer2.content"></textarea>
                        <button @click="answer2Answer(obj.id,idx)">回复</button>
>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
                    </div>

                </div>
            </td>
        </tr>
        </tbody>
    </table>
</div>
</body>
<script>
    new Vue({
        el: '#app',
        data: {
<<<<<<< HEAD
            commentid:"",
            replayid:"",
            respMap: {blog:{comments:[]},body:{}},
            replay:{content:""},
            comment:{content:""},
            comments: [],

=======
            respMap: {},
            <!--answers:一个评论里面的所有回复-->
            answers: [],
            <!--answer: 上传到后台的answer对象-->
            answer: {},
            answerid: "",
            <!--answerid2: 给后端判断是0就是回复评论博客的评论,否则就是回复别人的评论 -->
            answerid2: "0",
            answer2: {},
>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
        },
        methods: {
            //点赞
            addLike(){
                var that = this
                var blogid = sessionStorage.getItem("blogid");
<<<<<<< HEAD
                axios.get("/api/user/blog/addLike/" + blogid).then(function (resp) {
=======
                axios.get("/api/blog/addLike/" + blogid).then(function (resp) {
>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
                    if (resp.data.code ==401 ) {
                        that.$message({
                            showClose: true,
                            offset: 100,
                            message: resp.data.msg,
                            type: 'warning'
                        });
                    }
                    if (resp.data.code ==200 ) {
                        that.respMap.blog.likenum = that.respMap.blog.likenum+1
                    }

                })
            },
            //查找某篇博客
            findOneBlog() {
                var that = this
                var blogid = sessionStorage.getItem("blogid");
                console.log("blogid==")
                console.log(blogid)
                axios.get("/api/public/findOneBlog/" + blogid).then(function (resp) {
                    that.respMap = resp.data.data;
                    console.log("respMap==")
                    console.log(that.respMap)
                })
            },
            //根据博客id查找它里面的所有评论
<<<<<<< HEAD
            findCommentsByBlogId() {
                var that = this
                var blogid = sessionStorage.getItem("blogid");
                console.log("blogid==")
                console.log(blogid)
                axios.get("/api/public/findCommentsByBlogId/" + blogid).then(function (resp) {
                    that.respMap.blog.comments = resp.data.data;
                    console.log("comments==")
                    console.log(that.comments)
                })
            },
            //评论博客
            commentOnBlog() {
                var that = this
                var blogid = sessionStorage.getItem("blogid");
                var comment ={content:this.comment.content}
                axios({
                    url: "/api/user/comment/commentOnBlog/" + blogid,
                    method: "post",
                    headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                    params: comment
                }).then(function (resp) {
                    console.log("resp.data.data==")
                    console.log(resp.data.data)
                    console.log("comments==")
                    console.log(that.comments)
                    if(that.respMap.blog.comments==null){
                        that.findCommentsByBlogId(sessionStorage.getItem("blogid"))
                    }else{
                        that.respMap.blog.comments.unshift(resp.data.data)
                    }

                    that.respMap.blog.commentnum = that.respMap.blog.commentnum + 1
                    that.comment.content=""


                })


=======
            findAnswersByBlogId() {
                var that = this
                var blogid = sessionStorage.getItem("blogid");
                axios.get("/api/public/findAnswersByBlogId/" + blogid).then(function (resp) {
                    that.answers = resp.data.data;
                    console.log("answers==")
                    console.log(that.answers)
                })
            },
            //评论博客
            answer2Blog() {
                var that = this
                var blogid = sessionStorage.getItem("blogid");
                axios({
                    url: "/api/answer/answer2Blog/" + blogid,
                    method: "post",
                    headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                    params: this.answer
                }).then(function (resp) {
                    that.answers.unshift(resp.data.data)
                    console.log("resp.data.data==")
                    console.log(resp.data.data)
                    that.respMap.blog.answernum = that.respMap.blog.answernum + 1
                    that.answer.content=""
                })
>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
            },
            //添加阅读数
            addReadnum() {
                var blogid = sessionStorage.getItem("blogid");
                axios.get("/api/public/addReadNum/" + blogid).then(function (resp) {

                })
            },
            //让this.answerid等于当前点击回复的answerid(为了显示评论框)--》<div v-if="answerid==obj.id">
<<<<<<< HEAD
            changeCommentid(id) {
                this.commentid = id
                this.replayid="0"
            },
            changeCommentid2(commentid,replayid) {
                this.commentid = commentid
                this.replayid = replayid
            },
            //回复别人的评论
            replay2Comment(commentid,idx) {
                var that = this
                axios({
                    url: "/api/user/comment/replay2Comment/" + commentid + "/" + this.replayid,
                    method: "post",
                    headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                    params: this.replay
                }).then(function (resp) {
                    that.replay.content=""
                    if (that.respMap.blog.comments[idx].replays!=null){
                        that.respMap.blog.comments[idx].replays.push(resp.data.data);
                    } else {
                        axios.get("/api/user/comment/getReplays/"+commentid).then(function (resp) {
                            // that.answers[idx].answers=resp.data.data.reverse()
                            that.respMap.blog.comments[idx].replays=resp.data.data
=======
            replay(id) {
                this.answerid = id
            },
            replay2(answerid,answerid2) {
                this.answerid = answerid
                this.answerid2 = answerid2
            },
            //回复别人的评论
            answer2Answer(groupid, idx) {
                var that = this
                console.log("idx==" + idx)
                console.log("this.answer2==")
                console.log(this.answer2)
                axios({
                    url: "/api/answer/answer2Answer/" + groupid + "/" + this.answerid2,
                    method: "post",
                    headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'},
                    params: this.answer2
                }).then(function (resp) {
                    that.answer2.content=""
                    console.log("answers==")
                    console.log(that.answers[idx])
                    if (that.answers[idx].answers!=null){
                        that.answers[idx].answers.unshift(resp.data.data);
                    } else {
                        axios.get("/api/answer/getAnswers/"+groupid).then(function (resp) {
                            // that.answers[idx].answers=resp.data.data.reverse()
                            that.answers[idx].answers=resp.data.data
>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
                            console.log("data:answers=")
                            console.log(resp.data.data)
                        })
                    }


                })


            }

        },
        mounted: function () {
            this.findOneBlog();
<<<<<<< HEAD
            this.findCommentsByBlogId();
=======
            this.findAnswersByBlogId();
>>>>>>> a254f66694e58548627c0548f6e222a03570bbfd
            this.addReadnum();
        }
    })
</script>
</html>